//
//  ViewController.m
//  Video_Signal
//
//  Created by Justsoso on 16/4/2.
//  Copyright © 2016年 Justsoso. All rights reserved.
//

#import "ViewController.h"

#import <CoreLocation/CoreLocation.h>

#import "NetManager.h"

@interface ViewController ()<CLLocationManagerDelegate>
{
    NSString *longitude;
    NSString *latityde;
    
}

@property (strong,nonatomic) CLLocationManager *locationManager;

@property (nonatomic,strong) NSArray *list;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.locationManager = [[CLLocationManager alloc] init];
    
    // 精度
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    // 代理人
    self.locationManager.delegate = self;
    // 更新距离
    self.locationManager.distanceFilter = 10.0f;
    // 请求用户权限
    [self.locationManager requestWhenInUseAuthorization];
    // 启动定位
    [self.locationManager startUpdatingLocation];
    
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    // 得到的经纬度
    CLLocation *newLocation = [locations lastObject];
    longitude = [NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
    latityde = [NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
    
    [self.locationManager stopUpdatingLocation];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSString *location = [NSString stringWithFormat:@"%@,%@",longitude,latityde];
    [NetManager requestByVideos:location successBlock:^(NSArray *list) {
        self.list = list;
    } failBlock:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

@end
